package dai.learn.write.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * 写数据的工具
 * @author daify
 * @create 2019-03-22 11:23
 **/
public class WriteDataUtils {

    /**
     * 获得表格头
     * @return
     */
    public static List<String> getTitle() {
        List<String> titles = new ArrayList <String>();
        titles.add("序号");
        titles.add("名称");
        titles.add("占位符");
        return titles;
    }

    /**
     * 获得假数据
     * @param max
     * @return
     */
    public static List<List<String>> getValues(int max) {
        List<List<String>> rest = new ArrayList <List <String>>();
        for (int i = 0; i < max; i++) {
            List<String> item = new ArrayList <String>();
            item.add(String.valueOf(i));
            item.add("名称" + String.valueOf(i));
            item.add("占位符" + String.valueOf(i));
            rest.add(item);
        }
        return rest;
    }

    /**
     * 将数据进行分组
     * @param data
     * @param groupNum
     * @return
     */
    public static List<List <List <String>>> groupData(List<List<String>> data,
                                       Integer groupNum) {
        int all = data.size();
        int other = all%groupNum;
        int groupItemNum = all/groupNum;
        List<List <List <String>>> runList = new ArrayList <List <List <String>>>();
        while (data == null || data.size() > 0) {
            if (data.size() <= other + groupItemNum) {
                List <List <String>> lists = data.subList(0, data.size());
                List <List <String>> item = new ArrayList <List <String>>();
                item.addAll(lists);
                runList.add(item);
                data.removeAll(item);
            } else {
                List <List <String>> lists = data.subList(0, groupItemNum);
                List <List <String>> item = new ArrayList <List <String>>();
                item.addAll(lists);
                runList.add(item);
                data.removeAll(item);
            }
        }
        return runList;
    }
}
